package com.yeban.javase.day12.test.streamtest;

import java.util.Arrays;
import java.util.List;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/22
 *
 * 10.将员工按照工资由低到高（工资一样则按年龄由小到大）排序，显示名字
 */
public class StreamTest10 {

    public static void main(String[] args) {
        List<Employee4> employees = Arrays.asList (
                new Employee4 ("zhansan", 7500.0),
                new Employee4 ("lisi", 8200.0),
                new Employee4 ("zhouba", 9000.0),
                new Employee4 ("wangwu", 9000.0),
                new Employee4 ("zhaoliu", 7800.0),
                new Employee4 ("sunqi", 10000.0),
                new Employee4 ("lixiang", 10000.0));

        // 重写自定义类的比较器
        employees.stream().sorted().map(Employee4::getName).forEach(System.out::println);
    }
}


class Employee4 implements Comparable<Employee4> {
    private String name;
    private Double salary;

    public Employee4() {
    }

    public Employee4(String name, Double salary) {
        this.name = name;
        this.salary = salary;
    }

    @Override
    public int compareTo(Employee4 o) {
        if(this.salary.equals(o.salary)) {
            return this.name.compareTo(o.name);
        }
        return this.salary.compareTo(o.salary);
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return salary
     */
    public Double getSalary() {
        return salary;
    }

    /**
     * 设置
     * @param salary
     */
    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public String toString() {
        return "Employee{name = " + name + ", salary = " + salary + "}";
    }
}
